#include "lvgl.h"
#include "img_def.h"
#include "lv_common_function.h"


LV_FONT_DECLARE(Number_HarmonyOS_bpp4_20px);
LV_FONT_DECLARE(Number_HarmonyOS_bpp4_16px);
LV_FONT_DECLARE(Number_HarmonyOS_bpp4_12px);
LV_FONT_DECLARE(Number_HarmonyOS_bpp4_36px);
LV_FONT_DECLARE(Number_HarmonyOS_bpp4_44px);

#define     LV_FONT_SMALL_NUMBER_20PX     &Number_HarmonyOS_bpp4_20px
#define     LV_FONT_SMALL_NUMBER_16PX     &Number_HarmonyOS_bpp4_16px
#define     LV_FONT_SMALL_NUMBER_12PX     &Number_HarmonyOS_bpp4_12px
#define     LV_FONT_BIG_NUMBER_44PX       &Number_HarmonyOS_bpp4_44px
#define     LV_FONT_MEDIUM_NUMBER_36PX    &Number_HarmonyOS_bpp4_36px


static lv_timer_t *refresh_timer=NULL;
static uint8_t background_style = 1;

LV_ATTRIBUTE_LARGE_CONST static const lv_img_dsc_t* panel_bg1_src[6] =
{
    IMG_INSTRUMENT_BG1_1,
    IMG_INSTRUMENT_BG1_2,
    IMG_INSTRUMENT_BG1_3,
    IMG_INSTRUMENT_BG1_4,
    IMG_INSTRUMENT_BG1_5,
};

LV_ATTRIBUTE_LARGE_CONST static const lv_img_dsc_t* panel_bg2_src[6] =
{
    IMG_INSTRUMENT_BG2_1,
    IMG_INSTRUMENT_BG2_2,
    IMG_INSTRUMENT_BG2_3,
    IMG_INSTRUMENT_BG2_4,
    IMG_INSTRUMENT_BG2_5,
};

LV_ATTRIBUTE_LARGE_CONST static const lv_img_dsc_t* left_img_src[2] =
{
    IMG_INSTRUMENT_ICO13,
    IMG_INSTRUMENT_ICO14,
};

LV_ATTRIBUTE_LARGE_CONST static const lv_img_dsc_t* right_img_src[2] =
{
    IMG_INSTRUMENT_ICO9,
    IMG_INSTRUMENT_ICO10,
};

LV_ATTRIBUTE_LARGE_CONST static const lv_img_dsc_t* batt_black_img_src[5] =
{
    IMG_INSTRUMENT_BATT_ICO1,
    IMG_INSTRUMENT_BATT_ICO2,
    IMG_INSTRUMENT_BATT_ICO3,
    IMG_INSTRUMENT_BATT_ICO4,
    IMG_INSTRUMENT_BATT_ICO5
};

static uint32_t odb_val = 660;
static uint32_t trip_val = 1770;

static uint8_t dir_sw_flags=0;
static uint8_t dir_cnt=0;
static uint8_t speed_val=50;
static uint8_t right_battery_val=20;
static uint8_t left_battery_val=20;

static int speed_angle=2400;
static uint32_t background_sw =0 ;
void fr_lv_instrument_panel_func(lv_obj_t *parent, lv_point_t *top);



void lv_img_big_disp(lv_obj_t* parent, const lv_img_dsc_t **src , lv_coord_t x, lv_coord_t y,uint8_t img_num,uint8_t start)
{
    lv_obj_t *cont1 = lv_obj_create(parent);
    lv_obj_remove_style_all(cont1);
    lv_obj_clear_flag(cont1, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_scrollbar_mode(cont1, LV_SCROLLBAR_MODE_OFF);
    //lv_obj_set_size(cont1,LV_PCT(100),LV_PCT(100));
    lv_obj_set_style_bg_color(cont1,lv_color_black(),0);
    lv_obj_set_size(cont1,LV_SIZE_CONTENT,LV_SIZE_CONTENT);
    lv_obj_align(cont1,LV_ALIGN_TOP_LEFT,x,y);
    lv_obj_t *old_obj = NULL;
    for (uint8_t i = 0; i < img_num; i++)
    {
        lv_obj_t *img1 = lv_img_create(cont1);
        lv_img_set_src(img1,src[start+i]);
        if(i == 0)
            lv_obj_set_pos(img1,0,0);
        else
            lv_obj_align_to(img1,old_obj,LV_ALIGN_OUT_BOTTOM_LEFT,0,0);
        old_obj = img1;
    }
    lv_obj_clear_flag(cont1,LV_OBJ_FLAG_CLICKABLE);
}

lv_obj_t* lv_img_big_create(lv_obj_t* parent, const lv_img_dsc_t **src , lv_coord_t x, lv_coord_t y,uint8_t img_num,uint8_t start)
{
    lv_obj_t *cont1 = lv_obj_create(parent);
    lv_obj_remove_style_all(cont1);
    lv_obj_clear_flag(cont1, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_scrollbar_mode(cont1, LV_SCROLLBAR_MODE_OFF);
    //lv_obj_set_size(cont1,LV_PCT(100),LV_PCT(100));
    lv_obj_set_style_bg_color(cont1,lv_color_black(),0);
    lv_obj_set_size(cont1,LV_SIZE_CONTENT,LV_SIZE_CONTENT);
    //lv_obj_align(cont1,LV_ALIGN_TOP_LEFT,x,y);
    lv_obj_t *old_obj = NULL;

    for(uint8_t i = 0; i < img_num; i++)
    {
        lv_obj_t *img1 = lv_img_create(cont1);
        lv_img_set_src(img1,src[start+i]);
        if(i == 0)
            lv_obj_set_pos(img1,0,0);
        else
            lv_obj_align_to(img1,old_obj,LV_ALIGN_OUT_BOTTOM_LEFT,0,0);
        old_obj = img1;
    }
    return cont1;

}

void refresh_timer_cb(lv_timer_t *t)
{
    lv_obj_t *parent = t->user_data;
    if(!lv_obj_is_valid(parent))
    return;
    if(++background_sw>100)
    {
        background_sw = 0;
        background_style^=1;
        lv_timer_del(refresh_timer);
        refresh_timer = NULL;
        lv_obj_clean(parent);
        fr_lv_instrument_panel_func(parent,NULL);
        return;
    }
	lv_obj_t *left_img = lv_obj_get_child(parent,1);
    lv_obj_t *right_img = lv_obj_get_child(parent,2);
    lv_obj_t *odb_lab = lv_obj_get_child(parent,6);
    lv_obj_t *trip_lab = lv_obj_get_child(parent,7);

    lv_obj_t *wiper_img = lv_obj_get_child(parent,3);//5
    lv_obj_t *led_ico1_img = lv_obj_get_child(parent,4);//6
    lv_obj_t *led_ico2_img = lv_obj_get_child(parent,5);//7
    lv_obj_t * hand_img = lv_obj_get_child(parent, lv_obj_get_child_cnt(parent)-4);
    lv_obj_t *speed_lab = lv_obj_get_child(parent,lv_obj_get_child_cnt(parent)-2);

    lv_obj_t *right_slider_battery = lv_obj_get_child(parent,10);//10
    lv_obj_t *left_slider_battery = lv_obj_get_child(parent,11);//11
    lv_img_set_angle(hand_img,speed_angle);
    speed_angle+=100;
    if(speed_angle>4800)
    speed_angle=2400;
    if(!dir_sw_flags)
    {
        lv_img_set_src(left_img,left_img_src[1]);
        lv_img_set_src(right_img,right_img_src[0]);
        lv_obj_add_flag(wiper_img,LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(led_ico1_img,LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(led_ico2_img,LV_OBJ_FLAG_HIDDEN);
    }else{
        lv_img_set_src(left_img,left_img_src[0]);
        lv_img_set_src(right_img,right_img_src[1]);
        lv_obj_clear_flag(wiper_img,LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(led_ico1_img,LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(led_ico2_img,LV_OBJ_FLAG_HIDDEN);
    }
    if(++dir_cnt>15)
    {
        dir_cnt = 0;
        dir_sw_flags^=1;
        odb_val++;
        trip_val++;
    }
    lv_label_set_text_fmt(speed_lab,"%d",speed_val);
    lv_label_set_text_fmt(odb_lab,"%d",odb_val);
    lv_label_set_text_fmt(trip_lab,"%d",trip_val);

    lv_slider_set_value(left_slider_battery, left_battery_val, LV_ANIM_OFF);
    lv_slider_set_value(right_slider_battery, right_battery_val, LV_ANIM_OFF);
    lv_label_set_text_fmt(lv_obj_get_child(parent,13),"%d%%",(int)right_battery_val);
    lv_label_set_text_fmt(lv_obj_get_child(parent,12),"%d%%",(int)left_battery_val);
    left_battery_val+=5;
    left_battery_val%=100;
    right_battery_val+=5;
    right_battery_val%=100;

    //speed_val++;
    //speed_val%=100;
    speed_val = (speed_angle-2400)/24;
}

static inline lv_color_t get_label_color(void)
{
    if(background_style==0)
    {
       return lv_color_hex(0xffffff);
    }
    else{
       return lv_color_hex(0x00);
    }
}


#define M_PI 3.14
static int center_x = 242, center_y = 119;
static int radius = 51;
static double start_angle = 0;
static double end_angle = 0;
static float progress =0.0;
#define TEST_FUN      0

void move_arrow_task_cb(lv_timer_t *t) {
	start_angle = atan2(center_y - 143, 199 - center_x) * 180 / M_PI;
	end_angle = atan2(center_y - 143, 284 - center_x) * 180 / M_PI;
    lv_obj_t *parent = t->user_data;
    if(!lv_obj_is_valid(parent))
    return;
    //current_angle-=1;
    int current_angle = start_angle - progress * (start_angle + 390);
    int x = center_x + radius * cos(current_angle * M_PI / 180.0);
    int y = center_y - radius * sin(current_angle * M_PI / 180.0);
    lv_obj_t *arrow = lv_obj_get_child(parent, 4);
    lv_obj_set_pos(arrow, x, y);
    printf("current_angle:%d x:%d y:%d\r\n",current_angle,x,y);
    progress += 0.01;
    if (progress > 1.0) {
        progress = 0.0;
    }
}

static void slider1_change_cb(lv_event_t *e)
{
    lv_obj_t *slider = lv_event_get_target(e);
    lv_event_code_t event = lv_event_get_code(e);
    lv_obj_t *label = e->user_data;
    if(!lv_obj_is_valid(slider)||!lv_obj_is_valid(label))
    return;
    if(event == LV_EVENT_VALUE_CHANGED)
    {
        lv_label_set_text_fmt(label,"%d%%",(int)lv_slider_get_value(slider));
        printf("event_slider:%d \n", (int)lv_slider_get_value(slider));
    }
}

static void slider2_change_cb(lv_event_t *e)
{
    lv_obj_t *slider = lv_event_get_target(e);
    lv_event_code_t event = lv_event_get_code(e);
    lv_obj_t *label = e->user_data;
    if(!lv_obj_is_valid(slider)||!lv_obj_is_valid(label))
    return;
    if(event == LV_EVENT_VALUE_CHANGED)
    {
        lv_label_set_text_fmt(label,"%d%%",(int)lv_slider_get_value(slider));
        printf("event_slider:%d \n", (int)lv_slider_get_value(slider));
    }
}
#if 1

LV_IMG_DECLARE(batt_full_gren);
LV_IMG_DECLARE(batt_full_yellow);

void fr_lv_instrument_panel_func(lv_obj_t *parent, lv_point_t *top)
{
	
	if(!lv_obj_is_valid(parent))
	return;
	UI_PARENT_INIT(parent);
	if(background_style==0)
	{
		lv_obj_t* panel_bg_img = lv_img_big_create(parent,panel_bg1_src,0,0,5,0);//0
	}
	else{
		lv_obj_t* panel_bg_img = lv_img_big_create(parent,panel_bg2_src,0,0,5,0);//0
	}

	lv_obj_t *left_img = lv_img_create(parent);//1
	lv_img_set_src(left_img,left_img_src[1]);
	lv_obj_align(left_img,LV_ALIGN_TOP_LEFT,50,10);
	lv_obj_t *right_img = lv_img_create(parent);//2
	lv_img_set_src(right_img,right_img_src[1]);
	lv_obj_align(right_img,LV_ALIGN_TOP_RIGHT,-50,10);
    #if(TEST_FUN==1)
    lv_obj_t *dot_obj = lv_btn_create(parent);
    lv_obj_set_size(dot_obj,3,3);
    lv_obj_set_style_pad_all(dot_obj,0,0);
    lv_obj_set_style_radius(dot_obj,1,0);
    lv_obj_set_style_bg_color(dot_obj,lv_color_make(0xff, 0, 0),0);
    lv_obj_set_pos(dot_obj,197,145);
    //lv_obj_add_flag(dot_obj,LV_OBJ_FLAG_HIDDEN);
    lv_timer_create(move_arrow_task_cb,100,parent);
    return;
    #endif
    lv_obj_t *wiper_img = lv_img_create(parent);//3
	lv_img_set_src(wiper_img,IMG_INSTRUMENT_ICO3);
	lv_obj_align_to(wiper_img,left_img,LV_ALIGN_OUT_RIGHT_MID,20,0);

	lv_obj_t *led_ico1_img = lv_img_create(parent);//4
	lv_img_set_src(led_ico1_img,IMG_INSTRUMENT_ICO11);
	lv_obj_align_to(led_ico1_img,right_img,LV_ALIGN_OUT_LEFT_MID,-10,0);

	lv_obj_t *led_ico2_img = lv_img_create(parent);//5
	lv_img_set_src(led_ico2_img,IMG_INSTRUMENT_ICO7);
	lv_obj_align_to(led_ico2_img,led_ico1_img,LV_ALIGN_OUT_LEFT_MID,-10,0);

    lv_obj_t * trip_lab = lv_label_create(parent);//6
    lv_obj_set_style_text_color(trip_lab,get_label_color(),0);
    lv_obj_set_style_text_font(trip_lab,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(trip_lab, LV_ALIGN_BOTTOM_MID, 140, -10);
    lv_label_set_text_fmt(trip_lab,"%d",trip_val);

    lv_obj_t * odb_lab = lv_label_create(parent);//7
    lv_obj_set_style_text_color(odb_lab,get_label_color(),0);
    lv_obj_set_style_text_font(odb_lab,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(odb_lab, LV_ALIGN_BOTTOM_LEFT, 110, -10);
    lv_label_set_text_fmt(odb_lab,"%d",odb_val);

     lv_obj_t *left_batt_img = lv_img_create(parent);//8
 	lv_img_set_src(left_batt_img,IMG_BATT_EMPTY);
    lv_obj_align(left_batt_img,LV_ALIGN_LEFT_MID,55,0);

    lv_obj_t *right_batt_img = lv_img_create(parent);//9
 	lv_img_set_src(right_batt_img,IMG_BATT_EMPTY);
    lv_obj_align(right_batt_img,LV_ALIGN_RIGHT_MID,-55,0);

    lv_obj_t *right_slider_battery = lv_slider_create(parent);//10
    lv_slider_set_value(right_slider_battery, 50, LV_ANIM_OFF);
    if(lv_slider_get_mode(right_slider_battery) == LV_SLIDER_MODE_RANGE)
        lv_slider_set_left_value(right_slider_battery, 0,LV_ANIM_OFF);
    lv_obj_set_width(right_slider_battery, 30);
    lv_obj_set_height(right_slider_battery, 62);
    lv_obj_align(right_slider_battery,LV_ALIGN_RIGHT_MID,-55,0);
    lv_obj_set_style_radius(right_slider_battery,0,LV_PART_MAIN);
	lv_obj_set_style_radius(right_slider_battery,0,LV_PART_INDICATOR);
    //lv_obj_set_align(ui_Slider_Battery, LV_ALIGN_CENTER);
    lv_obj_set_style_bg_color(right_slider_battery, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(right_slider_battery, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(right_slider_battery, lv_color_hex(0xFFFFFF), LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(right_slider_battery, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_img_src(right_slider_battery, &batt_full_gren, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(right_slider_battery, lv_color_hex(0xFFFFFF), LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(right_slider_battery, 0, LV_PART_KNOB | LV_STATE_DEFAULT);

    lv_obj_t *left_slider_battery = lv_slider_create(parent);//11
    lv_slider_set_value(left_slider_battery, 20, LV_ANIM_OFF);
    if(lv_slider_get_mode(left_slider_battery) == LV_SLIDER_MODE_RANGE)
        lv_slider_set_left_value(left_slider_battery, 0,LV_ANIM_OFF);
    lv_obj_set_width(left_slider_battery, 30);
    lv_obj_set_height(left_slider_battery, 62);
    lv_obj_align(left_slider_battery,LV_ALIGN_LEFT_MID,55,0);
    lv_obj_set_style_radius(left_slider_battery,0,LV_PART_MAIN);
	lv_obj_set_style_radius(left_slider_battery,0,LV_PART_INDICATOR);
    lv_obj_set_style_bg_color(left_slider_battery, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(left_slider_battery, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(left_slider_battery, lv_color_hex(0xFFFFFF), LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(left_slider_battery, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_img_src(left_slider_battery, &batt_full_yellow, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(left_slider_battery, lv_color_hex(0xFFFFFF), LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(left_slider_battery, 0, LV_PART_KNOB | LV_STATE_DEFAULT);

    lv_obj_t * left_batt_val = lv_label_create(parent);//12
    lv_obj_set_style_text_color(left_batt_val,lv_color_make(250,198,13),0);
    lv_obj_set_style_text_font(left_batt_val,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(left_batt_val, left_batt_img,LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
    lv_label_set_text_fmt(left_batt_val,"%d%%",20);

    lv_obj_t * right_batt_val = lv_label_create(parent);//13
    lv_obj_set_style_text_color(right_batt_val,lv_color_make(8,255,74),0);
    lv_obj_set_style_text_font(right_batt_val,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(right_batt_val, right_batt_img,LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
    lv_label_set_text_fmt(right_batt_val,"%d%%",50);

    lv_obj_add_event_cb(right_slider_battery, slider1_change_cb, LV_EVENT_VALUE_CHANGED, (void*)right_batt_val);
    lv_obj_add_event_cb(left_slider_battery, slider2_change_cb, LV_EVENT_VALUE_CHANGED, (void*)left_batt_val);

    lv_obj_t * sta_lab = lv_label_create(parent);//10
    lv_obj_set_style_text_color(sta_lab,lv_color_make(11,250,73),0);
    lv_obj_set_style_text_font(sta_lab,LV_FONT_MEDIUM_NUMBER_36PX,0);
    lv_obj_align(sta_lab, LV_ALIGN_CENTER, 0, 55);
    lv_label_set_text(sta_lab,"R");

    lv_obj_t * ecu_label = lv_label_create(parent);//10
    lv_obj_set_style_text_color(ecu_label,lv_color_hex(0x00ff00),0);
    lv_obj_set_style_text_font(ecu_label,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(ecu_label, LV_ALIGN_BOTTOM_LEFT, 10, -10);
    lv_label_set_text(ecu_label,"ECU");

    lv_obj_t * odb_label = lv_label_create(parent);//11
    lv_obj_set_style_text_color(odb_label,get_label_color(),0);
    lv_obj_set_style_text_font(odb_label,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(odb_label,ecu_label, LV_ALIGN_OUT_RIGHT_BOTTOM, 10, 0);
    lv_label_set_text(odb_label,"ODB");

    lv_obj_t * ready_label = lv_label_create(parent);//12
    lv_obj_set_style_text_color(ready_label,lv_color_hex(0x00ff00),0);
    lv_obj_set_style_text_font(ready_label,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(ready_label, LV_ALIGN_BOTTOM_MID, 0, -15);
    lv_label_set_text(ready_label,"READY");


    lv_obj_t * trip_label = lv_label_create(parent);//
    lv_obj_set_style_text_color(trip_label,get_label_color(),0);
    lv_obj_set_style_text_font(trip_label,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align(trip_label, LV_ALIGN_BOTTOM_MID, 80, -10);
    lv_label_set_text(trip_label,"TRIP");

    lv_obj_t * trip_uint = lv_label_create(parent);//
    lv_obj_set_style_text_color(trip_uint,get_label_color(),0);
    lv_obj_set_style_text_font(trip_uint,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(trip_uint,trip_lab, LV_ALIGN_OUT_RIGHT_BOTTOM, 10, -2);
    lv_label_set_text(trip_uint,"KM");

    lv_obj_t * odb_uint = lv_label_create(parent);//
    lv_obj_set_style_text_color(odb_uint,get_label_color(),0);
    lv_obj_set_style_text_font(odb_uint,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(odb_uint,odb_lab, LV_ALIGN_OUT_RIGHT_BOTTOM, 15, -2);
    lv_label_set_text(odb_uint,"KM");


    lv_obj_t * left_batt_lab = lv_label_create(parent);//
    lv_obj_set_style_text_color(left_batt_lab,lv_color_make(137,137,137),0);
    lv_obj_set_style_text_font(left_batt_lab,LV_FONT_SMALL_NUMBER_12PX,0);
    lv_obj_align_to(left_batt_lab, left_batt_img,LV_ALIGN_OUT_TOP_MID, 0, -5);
    lv_label_set_text(left_batt_lab,"BAT1");

    lv_obj_t * right_batt_lab= lv_label_create(parent);//
    lv_obj_set_style_text_color(right_batt_lab,lv_color_make(137,137,137),0);
    lv_obj_set_style_text_font(right_batt_lab,LV_FONT_SMALL_NUMBER_12PX,0);
    lv_obj_align_to(right_batt_lab, right_batt_img,LV_ALIGN_OUT_TOP_MID, 0, -5);
    lv_label_set_text(right_batt_lab,"BAT2");

    lv_obj_t *left_ico1 = lv_img_create(parent);
 	lv_img_set_src(left_ico1,IMG_INSTRUMENT_ICO1);
    lv_obj_align(left_ico1,LV_ALIGN_LEFT_MID,100,-25);

    lv_obj_t *left_ico2 = lv_img_create(parent);
 	lv_img_set_src(left_ico2,IMG_INSTRUMENT_ICO5);
    lv_obj_align_to(left_ico2,left_ico1,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *left_ico3 = lv_img_create(parent);
    lv_img_set_src(left_ico3,IMG_INSTRUMENT_ICO2);
    lv_obj_align_to(left_ico3,left_ico2,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *right_ico1 = lv_img_create(parent);
 	lv_img_set_src(right_ico1,IMG_INSTRUMENT_ICO6);
    lv_obj_align(right_ico1,LV_ALIGN_RIGHT_MID,-100,-25);

    lv_obj_t *right_ico2 = lv_img_create(parent);
 	lv_img_set_src(right_ico2,IMG_INSTRUMENT_ICO12);
    lv_obj_align_to(right_ico2,right_ico1,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *right_ico3 = lv_img_create(parent);
    lv_img_set_src(right_ico3,IMG_INSTRUMENT_ICO4);
    lv_obj_align_to(right_ico3,right_ico2,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *hand_img = lv_img_create(parent);//4
 	lv_img_set_src(hand_img,IMG_CENTER_ARROWS);
 	lv_obj_align(hand_img,LV_ALIGN_CENTER,0,-50);
 	lv_img_set_pivot(hand_img, 5, 70);
    lv_img_set_angle(hand_img, 3200);
//    lv_obj_t *dot2_obj = lv_btn_create(parent);
//    lv_obj_set_size(dot2_obj,10,10);
//    lv_obj_set_style_pad_all(dot2_obj,0,0);
//    lv_obj_set_style_radius(dot2_obj,5,0);
//    lv_obj_set_style_bg_color(dot2_obj,lv_color_make(0x0, 0xff, 0),0);
//    lv_obj_set_pos(dot2_obj,242-5,119);
    lv_obj_t *arc_img = lv_img_create(parent);
    lv_obj_set_pos(arc_img,185,65);
    if(background_style==0)
    {
        lv_img_set_src(arc_img,IMG_CIRCULAR_BLACK);
    }else{
        lv_img_set_src(arc_img,IMG_CIRCULAR_WHITE);
    }
    lv_obj_t * speed_lab= lv_label_create(parent);//3
    lv_obj_set_style_text_color(speed_lab,lv_color_make(216,38,44),0);
    lv_obj_set_style_text_font(speed_lab,LV_FONT_BIG_NUMBER_44PX,0);
    lv_obj_align(speed_lab,LV_ALIGN_CENTER, 0, -20);
    lv_label_set_text_fmt(speed_lab,"%d",100);

    lv_obj_t * speed_uint = lv_label_create(parent);//
    lv_obj_set_style_text_color(speed_uint,get_label_color(),0);
    lv_obj_set_style_text_font(speed_uint,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align(speed_uint, LV_ALIGN_CENTER, 0, +10);
    lv_label_set_text(speed_uint,"km/h");

    refresh_timer = lv_timer_create(refresh_timer_cb,10,parent);

}

#else
void fr_lv_instrument_panel_func(lv_obj_t *parent, lv_point_t *top)
{

     //start_angle = -atan2(143 - center_y, 199 - center_x) * 180 / M_PI + 360; // �Զ�Ϊ��λ
    // end_angle = -atan2(143 - center_y, 284 - center_x) * 180 / M_PI + 360;   // �Զ�Ϊ��λ
    //start_angle = -atan2(143 - center_y, 199 - center_x) * 180 / M_PI + 360; // �Զ�Ϊ��λ
    //end_angle = -atan2(143 - center_y, 284 - center_x) * 180 / M_PI + 360;   // �Զ�Ϊ��λ

     start_angle = atan2(center_y - 143, 199 - center_x) * 180 / M_PI; // �Զ�Ϊ��λ
     end_angle = atan2(center_y - 143, 284 - center_x) * 180 / M_PI;   // �Զ�Ϊ��λ

     start_angle = -150;
    // start_angle = atan2(143 - center_y, 199 - center_x) * 180 / M_PI; // �Զ�Ϊ��λ
    // end_angle = atan2(143 - center_y, 284 - center_x) * 180 / M_PI;   // �Զ�Ϊ��λ
//    if (start_angle < 0) start_angle += 360;
//    if (end_angle < 0) end_angle += 360;
    printf("��ʼ�Ƕȣ�%lf ��\n", start_angle);
    printf("�����Ƕȣ�%lf ��\n", end_angle);
    if(!lv_obj_is_valid(parent))
    return;
    UI_PARENT_INIT(parent);
    if(background_style==0)
    {
        lv_obj_t* panel_bg_img = lv_img_big_create(parent,panel_bg1_src,0,0,5,0);//0
    }
    else{
        lv_obj_t* panel_bg_img = lv_img_big_create(parent,panel_bg2_src,0,0,5,0);//0
    }

	lv_obj_t *left_img = lv_img_create(parent);//1
	lv_img_set_src(left_img,left_img_src[1]);
	lv_obj_align(left_img,LV_ALIGN_TOP_LEFT,50,10);

 	lv_obj_t *right_img = lv_img_create(parent);//2
	lv_img_set_src(right_img,right_img_src[1]);
	lv_obj_align(right_img,LV_ALIGN_TOP_RIGHT,-50,10);

    lv_obj_t * speed_lab= lv_label_create(parent);//3
    lv_obj_set_style_text_color(speed_lab,lv_color_make(216,38,44),0);
    lv_obj_set_style_text_font(speed_lab,LV_FONT_BIG_NUMBER_44PX,0);
    lv_obj_align(speed_lab,LV_ALIGN_CENTER, 0, -20);
    lv_label_set_text_fmt(speed_lab,"%d",100);

    #if(TEST_FUN==1)
    lv_obj_t *dot_obj = lv_btn_create(parent);
    lv_obj_set_size(dot_obj,3,3);
    lv_obj_set_style_pad_all(dot_obj,0,0);
    lv_obj_set_style_radius(dot_obj,1,0);
    lv_obj_set_style_bg_color(dot_obj,lv_color_make(0xff, 0, 0),0);
    lv_obj_set_pos(dot_obj,197,145);
    #else
    lv_obj_t *arrows_img = lv_img_create(parent);//4
 	lv_img_set_src(arrows_img,IMG_INSTRUMENT_ICO8);
    lv_obj_set_pos(arrows_img,197,145);
    //lv_img_set_pivot(arrows_img, 50, 15);
    lv_timer_create(move_arrow_task_cb,100,parent);
    #endif


    lv_obj_t *wiper_img = lv_img_create(parent);//5
	lv_img_set_src(wiper_img,IMG_INSTRUMENT_ICO3);
	lv_obj_align_to(wiper_img,left_img,LV_ALIGN_OUT_RIGHT_MID,20,0);

	lv_obj_t *led_ico1_img = lv_img_create(parent);//6
	lv_img_set_src(led_ico1_img,IMG_INSTRUMENT_ICO11);
	lv_obj_align_to(led_ico1_img,right_img,LV_ALIGN_OUT_LEFT_MID,-10,0);

	lv_obj_t *led_ico2_img = lv_img_create(parent);//7
	lv_img_set_src(led_ico2_img,IMG_INSTRUMENT_ICO7);
	lv_obj_align_to(led_ico2_img,led_ico1_img,LV_ALIGN_OUT_LEFT_MID,-10,0);

    lv_obj_t * trip_lab = lv_label_create(parent);//8
    lv_obj_set_style_text_color(trip_lab,get_label_color(),0);
    lv_obj_set_style_text_font(trip_lab,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(trip_lab, LV_ALIGN_BOTTOM_MID, 140, -10);
    lv_label_set_text_fmt(trip_lab,"%d",trip_val);

    lv_obj_t * odb_lab = lv_label_create(parent);//9
    lv_obj_set_style_text_color(odb_lab,get_label_color(),0);
    lv_obj_set_style_text_font(odb_lab,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(odb_lab, LV_ALIGN_BOTTOM_LEFT, 110, -10);
    lv_label_set_text_fmt(odb_lab,"%d",odb_val);

    lv_obj_t * sta_lab = lv_label_create(parent);//10
    lv_obj_set_style_text_color(sta_lab,lv_color_make(11,250,73),0);
    lv_obj_set_style_text_font(sta_lab,LV_FONT_MEDIUM_NUMBER_36PX,0);
    lv_obj_align(sta_lab, LV_ALIGN_CENTER, 0, 55);
    lv_label_set_text(sta_lab,"R");

    lv_obj_t * ecu_label = lv_label_create(parent);//10
    lv_obj_set_style_text_color(ecu_label,lv_color_hex(0x00ff00),0);
    lv_obj_set_style_text_font(ecu_label,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(ecu_label, LV_ALIGN_BOTTOM_LEFT, 10, -10);
    lv_label_set_text(ecu_label,"ECU");

    lv_obj_t * odb_label = lv_label_create(parent);//11
    lv_obj_set_style_text_color(odb_label,get_label_color(),0);
    lv_obj_set_style_text_font(odb_label,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(odb_label,ecu_label, LV_ALIGN_OUT_RIGHT_BOTTOM, 10, 0);
    lv_label_set_text(odb_label,"ODB");

    lv_obj_t * ready_label = lv_label_create(parent);//12
    lv_obj_set_style_text_color(ready_label,lv_color_hex(0x00ff00),0);
    lv_obj_set_style_text_font(ready_label,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_obj_align(ready_label, LV_ALIGN_BOTTOM_MID, 0, -15);
    lv_label_set_text(ready_label,"READY");


    lv_obj_t * trip_label = lv_label_create(parent);//
    lv_obj_set_style_text_color(trip_label,get_label_color(),0);
    lv_obj_set_style_text_font(trip_label,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align(trip_label, LV_ALIGN_BOTTOM_MID, 80, -10);
    lv_label_set_text(trip_label,"TRIP");

    lv_obj_t * trip_uint = lv_label_create(parent);//
    lv_obj_set_style_text_color(trip_uint,get_label_color(),0);
    lv_obj_set_style_text_font(trip_uint,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(trip_uint,trip_lab, LV_ALIGN_OUT_RIGHT_BOTTOM, 10, -2);
    lv_label_set_text(trip_uint,"KM");

    lv_obj_t * odb_uint = lv_label_create(parent);//
    lv_obj_set_style_text_color(odb_uint,get_label_color(),0);
    lv_obj_set_style_text_font(odb_uint,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(odb_uint,odb_lab, LV_ALIGN_OUT_RIGHT_BOTTOM, 15, -2);
    lv_label_set_text(odb_uint,"KM");

    lv_obj_t *left_batt_img = lv_img_create(parent);
 	lv_img_set_src(left_batt_img,batt_black_img_src[2]);
    lv_obj_align(left_batt_img,LV_ALIGN_LEFT_MID,55,0);

    lv_obj_t *right_batt_img = lv_img_create(parent);
 	lv_img_set_src(right_batt_img,batt_black_img_src[3]);
    lv_obj_align(right_batt_img,LV_ALIGN_RIGHT_MID,-55,0);

    lv_obj_t * left_batt_val = lv_label_create(parent);//
    lv_obj_set_style_text_color(left_batt_val,lv_color_make(250,198,13),0);
    lv_obj_set_style_text_font(left_batt_val,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(left_batt_val, left_batt_img,LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
    lv_label_set_text_fmt(left_batt_val,"%d%%",50);

    lv_obj_t * right_batt_val = lv_label_create(parent);//
    lv_obj_set_style_text_color(right_batt_val,lv_color_make(8,255,74),0);
    lv_obj_set_style_text_font(right_batt_val,LV_FONT_SMALL_NUMBER_16PX,0);
    lv_obj_align_to(right_batt_val, right_batt_img,LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
    lv_label_set_text_fmt(right_batt_val,"%d%%",90);

    lv_obj_t * left_batt_lab = lv_label_create(parent);//
    lv_obj_set_style_text_color(left_batt_lab,lv_color_make(137,137,137),0);
    lv_obj_set_style_text_font(left_batt_lab,LV_FONT_SMALL_NUMBER_12PX,0);
    lv_obj_align_to(left_batt_lab, left_batt_img,LV_ALIGN_OUT_TOP_MID, 0, -5);
    lv_label_set_text(left_batt_lab,"BAT1");

    lv_obj_t * right_batt_lab= lv_label_create(parent);//
    lv_obj_set_style_text_color(right_batt_lab,lv_color_make(137,137,137),0);
    lv_obj_set_style_text_font(right_batt_lab,LV_FONT_SMALL_NUMBER_12PX,0);
    lv_obj_align_to(right_batt_lab, right_batt_img,LV_ALIGN_OUT_TOP_MID, 0, -5);
    lv_label_set_text(right_batt_lab,"BAT2");

//    lv_obj_t * arc = lv_arc_create(parent);//����Բ������
//    lv_obj_set_size(arc,105,105);
//    lv_arc_set_rotation(arc,0);                  //�������λ��
//    lv_arc_set_bg_angles(arc,0,360);             //���ýǶ�
//    lv_arc_set_range(arc,0,270);
//    lv_arc_set_change_rate(arc,1);
//    lv_obj_set_style_arc_width(arc, 2, LV_PART_MAIN);							// ���ñ�������Ĭ��״̬�µĿ���
//    lv_obj_set_style_arc_color(arc, lv_color_make(0,0,255), LV_PART_MAIN);
//    lv_obj_remove_style(arc,NULL,LV_PART_KNOB);  //�Ƴ���ʽ
//    lv_obj_clear_flag(arc,LV_OBJ_FLAG_CLICKABLE);//�����־λ
//    lv_obj_align(arc,LV_ALIGN_CENTER,0,-18);



    lv_obj_t *left_ico1 = lv_img_create(parent);
 	lv_img_set_src(left_ico1,IMG_INSTRUMENT_ICO1);
    lv_obj_align(left_ico1,LV_ALIGN_LEFT_MID,100,-25);

    lv_obj_t *left_ico2 = lv_img_create(parent);
 	lv_img_set_src(left_ico2,IMG_INSTRUMENT_ICO5);
    lv_obj_align_to(left_ico2,left_ico1,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *left_ico3 = lv_img_create(parent);
    lv_img_set_src(left_ico3,IMG_INSTRUMENT_ICO2);
    lv_obj_align_to(left_ico3,left_ico2,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *right_ico1 = lv_img_create(parent);
 	lv_img_set_src(right_ico1,IMG_INSTRUMENT_ICO6);
    lv_obj_align(right_ico1,LV_ALIGN_RIGHT_MID,-100,-25);

    lv_obj_t *right_ico2 = lv_img_create(parent);
 	lv_img_set_src(right_ico2,IMG_INSTRUMENT_ICO12);
    lv_obj_align_to(right_ico2,right_ico1,LV_ALIGN_OUT_BOTTOM_MID,0,10);

    lv_obj_t *right_ico3 = lv_img_create(parent);
    lv_img_set_src(right_ico3,IMG_INSTRUMENT_ICO4);
    lv_obj_align_to(right_ico3,right_ico2,LV_ALIGN_OUT_BOTTOM_MID,0,10);

   // refresh_timer = lv_timer_create(refresh_timer_cb,20,parent);

}
#endif
